package org.zoomdev.android.nfc;



import com.zoomdev.android.hex.HexUtil;

import java.util.Arrays;

public class ApduResponse {
    public static final short VALID_VALUE = 144;
    public static final ApduResponse OK = new ApduResponse(new byte[]{-112, 0});
    private byte[] src;

    public ApduResponse(byte[] src) {
        this.src = src;
    }

    public byte[] getData() {
        return Arrays.copyOf(this.src, this.src.length - 2);
    }

    public String getStr() {
        return HexUtil.encodeHexStr(this.src, this.src.length - 2);
    }

    public boolean isOk() {
        return this.getSw() == 144;
    }

    public short getSw() {
        return HexUtil.toShort(this.src, this.src.length - 2);
    }



    public ApduResponse validate() throws ApduException {
        short sw = this.getSw();
        if (sw != 144) {
            throw new ApduException(sw);
        } else {
            return this;
        }
    }

    public byte[] getRowData() {
        return this.src;
    }
}
